<template>
  <div class="CodePage">
    <div id="printDiv">
      <div class="qrcode" ref="qrCodeUrl"></div>
      <p>单号: {{ entity.BillId }}</p>
      <p>
        日期: {{ entity.CreateTime ? entity.CreateTime.substring(0, 10) : "" }}
      </p>
      <!-- <p style="text-align: center">
        {{ entity.Customer }}
      </p> -->
    </div>
    <p style="text-align: center; font-size: 12px; color: #000">
      签收码: {{ entity.SmsCode }}
    </p>
    <div style="text-align: center; margin-top: 20px">
      <el-button type="primary" plain v-print="printObj" style="width: 100px"
        >打 印</el-button
      >
    </div>
  </div>
</template>

<script>
import QRCode from "qrcodejs2";
export default {
  data() {
    return {
      printObj: { id: "printDiv", popTitle: "" },
      entity: {},
    };
  },
  mounted() {
    let qrcode = this.$route.query.QRCode;
    if (qrcode) {
      this.$http
        .post("/BO/BillList/GetBillData", { id: qrcode })
        .then((res) => {
          if (res.Success) {
            this.entity = res.Data;
            let arr = JSON.parse(this.entity.Content).printlist;
            let idx = arr.findIndex((item) => item.Key == "发货日期");
            if (idx > -1) this.entity.CreateTime = arr[idx].value
            JSON.parse(this.entity.Content).printlist[idx];
            this.creatQrCode(this.entity.QrCode);
          } else {
            this.$message.error(res.Msg);
          }
        });
    }
  },
  methods: {
    creatQrCode(text) {
      var qrcode = new QRCode(this.$refs.qrCodeUrl, {
        text, // 需要转换为二维码的内容
        width: 100,
        height: 100,
        colorDark: "#000000",
        colorLight: "#ffffff",
        correctLevel: QRCode.CorrectLevel.H,
      });
    },
  },
};
</script>

<style scoped lang="less">
.CodePage {
  padding-top: 100px;
}
#printDiv {
  display: flex;
  justify-content: center;
  flex-direction: column;
  align-items: center;
  color: #000;
  p {
    margin: 0;
    font-size: 12px;
    line-height: 2;
  }
}
.qrcode {
}
</style>